#include <stdio.h>
#include <string.h>
#define _ERROR_ROUTINE(s) fprintf(stderr, "Error: " s)

#define _S_ETYPE int
#define _S_PREFIX i_
#include "stack.c"

#define _S_ETYPE float
#define _S_PREFIX f_
#include "stack.c"

const char prompt[] = "stack > ";

int eatline()
{
    int c;
    while ((c = getchar()) != EOF && c != '\n')
        ;
    return c;
}

int main()
{
    i_stack s;
    f_stack fs;
    char cmd[1024];

    s = i_new(1024);
    fs = f_new(1024);

    printf("Welcome to c_temp stack\n%s", prompt);

    while (scanf("%s", cmd) == 1){
#define cmdis(s) (!strcmp(cmd, s))
        if       cmdis("pop"){
            printf("Popped: %d\n", i_pop(&s));
        }else if cmdis("fpop"){
            printf("Float popped: %f\n", f_pop(&fs));
        }else if cmdis("push"){
            int i;
            scanf("%d", &i);
            i_push(&s, i);
            printf("Pushed: %d\n", i);
        }else if cmdis("fpush"){ 
            float f;
            scanf("%f", &f);
            f_push(&fs, f);
            printf("Float pushed: %f\n", f);
        }else if cmdis("print"){
            i_print(s, "%d\n");
        }else if cmdis("fprint"){
            f_print(fs, "%f\n");
        }else if cmdis("top"){
            printf("Top==%d\n", s.top);
        }else if cmdis("ftop"){
            printf("Ftop==%d\n", fs.top);
        }else if cmdis("quit"){
            break;
        }else{
            printf("Unrecognized command: %s\n", cmd);
            if (eatline() == EOF) break;
        }

        printf("%s", prompt);
    }

    return 0;
}

